from PIL import Image, ImageDraw, ImageFont
import lib.layout
import config


class ImageLayout:
    def __init__(self, image, font_x=0, font_y=0):
        self.font_y = font_y
        self.font_x = font_x
        self.image = image

    def textView(self, x, y, text, font_file=config.font_path, font_size=24):
        draw = ImageDraw.Draw(self.image)
        # 设置字体，和字体大小
        font = ImageFont.truetype(font_file, font_size)
        font_x, font_y = font.getsize(text)
        draw.text((x, y), text, (255, 255, 255), font=font)
        del draw  # 删除画笔
        self.font_y = font_y
        self.font_x = font_x

    def get_font_x(self):
        return self.font_x

    def get_font_y(self):
        return self.font_y

    def save(self, image_name):
        self.image.save(image_name)

    def close(self):
        self.image.close()

    def exec(self):
        pass
